package com.dnjn.mes.biz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dnjn.mes.biz.domain.MesRecordBeat;
import com.dnjn.mes.biz.domain.MesRecordCapacity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalTime;
import java.util.List;

/**
 * <p>
 * 节拍表 Mapper 接口
 * </p>
 *
 * @author Amber
 * @since 2023-07-26
 */
public interface MesRecordBeatMapper extends BaseMapper<MesRecordBeat> {

    @Select("select * from mes_record_beat where TO_DAYS(create_time) = TO_DAYS(CURDATE()) and equipment_id=#{equipmentId} and DATE_FORMAT(create_time,'%H:%i:%s') BETWEEN  '08:00:00' and '20:00:00' order by create_time ")
    List<MesRecordBeat> getEarlyRecordBeatChart(@Param("equipmentId") Long equipmentId);

    @Select("select * from mes_record_beat where TO_DAYS(create_time) = TO_DAYS(CURDATE()) and (DATE_FORMAT(create_time,'%H:%i:%s') BETWEEN  '20:00:00' and '23:59:59' ) and equipment_id=#{equipmentId} or (TO_DAYS(create_time) - TO_DAYS(CURDATE()) = 1 and equipment_id=#{equipmentId} and DATE_FORMAT(create_time,'%H:%i:%s') < '08:00:00' ) ORDER BY create_time ")
    List<MesRecordBeat> getNightRecordBeatChart(@Param("equipmentId") Long equipmentId);


//    @Select(" select create_time,data_value from mes_record_beat where 1=1 and (DATE_FORMAT(create_time,'%Y-%m-%d') >= #{startLocalDateTime} and DATE_FORMAT(create_time,'%H:%i:%s') >= #{startTime}) and (DATE_FORMAT(create_time,'%Y-%m-%d') >= #{endLocalDateTime} and DATE_FORMAT(create_time,'%H:%i:%s') < #{endTime}) AND equipment_id = #{equipmentId} ORDER BY create_time")
    @Select(" select create_time,data_value from mes_record_beat where 1=1 and create_time >= #{startLocalDateTime} and create_time < #{endLocalDateTime} and equipment_id=#{equipmentId} ORDER BY create_time ")
    List<MesRecordBeat> getTrendsRecordBeatChart(@Param("equipmentId") long equipmentId, @Param("startTime")LocalTime startTime, @Param("endTime")LocalTime endTime,@Param("startLocalDateTime") String startLocalDateTime,@Param("endLocalDateTime") String endLocalDateTime);
}
